package tech.aistar.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.aistar.entity.*;
import tech.aistar.service.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: shuaiguo
 * @Date: 2020/10/02/13:24
 * @Description:
 */

@Controller
@RequestMapping("/Detail")
public class DetailInfoAction {
    @Autowired
    private IHouseService houseService;
    @Autowired
    private IAgentService agentService;
    @Autowired
    private ICostService costService;
    @Autowired
    private IAppointmentTimeService appointmentTimeService;
    @Autowired
    private ICotenancyRequireService cotenancyRequireService;
    @Autowired
    private IEnvironmentFacilityService environmentFacilityService;
    @Autowired
    private IEvaluateService evaluateService;
    @Autowired
    private IConcernService concernService;

    @RequestMapping("/studentxiangxi")
    public String detail1(HttpServletRequest request) {
        Tenant tenant= (Tenant) request.getSession().getAttribute("tenant");
        Integer tenant_id = tenant.getId();
        System.out.println(tenant_id);
        String house_id=null;
        if(request.getParameter("house_id")!=""){
            house_id=request.getParameter("house_id");
        }
        request.setAttribute("tenant_id",tenant_id);

        House house = houseService.selectById(Integer.valueOf(house_id));
        request.setAttribute("house", house);


        Cost cost = costService.findByhouseId(Integer.valueOf(house_id));

        request.setAttribute("cost", cost);

        AppointmentTime appointmentTime = appointmentTimeService.findByhouseId(Integer.valueOf(house_id));
        request.setAttribute("appointmentTime", appointmentTime);

        CotenancyRequire cotenancyRequire = cotenancyRequireService.findByhouseId(Integer.valueOf(house_id));
        request.setAttribute("cotenancyRequire", cotenancyRequire);

        EnvironmentFaclity environmentFaclity = environmentFacilityService.findByhouseId(Integer.valueOf(house_id));
        request.setAttribute("environmentFacility", environmentFaclity);


        Integer agent_id=houseService.selectagentByhouseId(Integer.valueOf(house_id));

        Agent agent = agentService.selectById(Integer.valueOf(agent_id));
        request.setAttribute("agent", agent);
        System.out.println(agent);

        Evaluate evaluate = evaluateService.findByagentId(Integer.valueOf(agent_id));
        request.setAttribute("evaluate", evaluate);

        Concern concern = concernService.selectById(tenant_id, Integer.valueOf(house_id));
        request.setAttribute("concern", concern);
        return "/rent_info/studentfangyuanxinxi";
    }

    @RequestMapping("/whitexiangxi")
    public String detail2(HttpServletRequest request) {
        Tenant tenant= (Tenant) request.getSession().getAttribute("tenant");
        Integer tenant_id = tenant.getId();
        System.out.println(tenant_id);
        String house_id=null;
        if(request.getParameter("house_id")!=""){
            house_id=request.getParameter("house_id");
        }
        request.setAttribute("tenant_id",tenant_id);

        House house = houseService.selectById(Integer.valueOf(house_id));
        request.setAttribute("house", house);


        Cost cost = costService.findByhouseId(Integer.valueOf(house_id));

        request.setAttribute("cost", cost);

        AppointmentTime appointmentTime = appointmentTimeService.findByhouseId(Integer.valueOf(house_id));
        request.setAttribute("appointmentTime", appointmentTime);

        CotenancyRequire cotenancyRequire = cotenancyRequireService.findByhouseId(Integer.valueOf(house_id));
        request.setAttribute("cotenancyRequire", cotenancyRequire);

        EnvironmentFaclity environmentFaclity = environmentFacilityService.findByhouseId(Integer.valueOf(house_id));
        request.setAttribute("environmentFacility", environmentFaclity);


        Integer agent_id=houseService.selectagentByhouseId(Integer.valueOf(house_id));

        Agent agent = agentService.selectById(Integer.valueOf(agent_id));
        request.setAttribute("agent", agent);
        System.out.println(agent);

        Evaluate evaluate = evaluateService.findByagentId(Integer.valueOf(agent_id));
        request.setAttribute("evaluate", evaluate);

        Concern concern = concernService.selectById(tenant_id, Integer.valueOf(house_id));
        request.setAttribute("concern", concern);
        return "/rent_info/whitefangyuanxinxi";
    }

    @RequestMapping("/hezuxiangxi")
    public String detail3(HttpServletRequest request) {
        Tenant tenant= (Tenant) request.getSession().getAttribute("tenant");
        Integer tenant_id = tenant.getId();
        System.out.println(tenant_id);
        String house_id=null;
        if(request.getParameter("house_id")!=""){
            house_id=request.getParameter("house_id");
        }
        request.setAttribute("tenant_id",tenant_id);

        House house = houseService.selectById(Integer.valueOf(house_id));
        request.setAttribute("house", house);


        Cost cost = costService.findByhouseId(Integer.valueOf(house_id));

        request.setAttribute("cost", cost);

        AppointmentTime appointmentTime = appointmentTimeService.findByhouseId(Integer.valueOf(house_id));
        request.setAttribute("appointmentTime", appointmentTime);

        CotenancyRequire cotenancyRequire = cotenancyRequireService.findByhouseId(Integer.valueOf(house_id));
        request.setAttribute("cotenancyRequire", cotenancyRequire);

        EnvironmentFaclity environmentFaclity = environmentFacilityService.findByhouseId(Integer.valueOf(house_id));
        request.setAttribute("environmentFacility", environmentFaclity);


        Integer agent_id=houseService.selectagentByhouseId(Integer.valueOf(house_id));

        Agent agent = agentService.selectById(Integer.valueOf(agent_id));
        request.setAttribute("agent", agent);
        System.out.println(agent);

        Evaluate evaluate = evaluateService.findByagentId(Integer.valueOf(agent_id));
        request.setAttribute("evaluate", evaluate);

        Concern concern = concernService.selectById(tenant_id, Integer.valueOf(house_id));
        request.setAttribute("concern", concern);
        return "/rent_info/hezufangyuanxinxi";
    }

    @RequestMapping("/zhengzuxiangxi")
    public String detail4(HttpServletRequest request) {
        Tenant tenant= (Tenant) request.getSession().getAttribute("tenant");
        Integer tenant_id = tenant.getId();
        System.out.println(tenant_id);
        String house_id=null;
        if(request.getParameter("house_id")!=""){
            house_id=request.getParameter("house_id");
        }
        request.setAttribute("tenant_id",tenant_id);

        House house = houseService.selectById(Integer.valueOf(house_id));
        request.setAttribute("house", house);


        Cost cost = costService.findByhouseId(Integer.valueOf(house_id));

        request.setAttribute("cost", cost);

        AppointmentTime appointmentTime = appointmentTimeService.findByhouseId(Integer.valueOf(house_id));
        request.setAttribute("appointmentTime", appointmentTime);

        CotenancyRequire cotenancyRequire = cotenancyRequireService.findByhouseId(Integer.valueOf(house_id));
        request.setAttribute("cotenancyRequire", cotenancyRequire);

        EnvironmentFaclity environmentFaclity = environmentFacilityService.findByhouseId(Integer.valueOf(house_id));
        request.setAttribute("environmentFacility", environmentFaclity);


        Integer agent_id=houseService.selectagentByhouseId(Integer.valueOf(house_id));

        Agent agent = agentService.selectById(Integer.valueOf(agent_id));
        request.setAttribute("agent", agent);
        System.out.println(agent);

        Evaluate evaluate = evaluateService.findByagentId(Integer.valueOf(agent_id));
        request.setAttribute("evaluate", evaluate);

        Concern concern = concernService.selectById(tenant_id, Integer.valueOf(house_id));
        request.setAttribute("concern", concern);

        return "/rent_info/zhengzufangyuanxinxi";
    }


}



